package com.lagou.edu.service.impl;

import com.lagou.edu.service.IMessageProduder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;

/**
 * @author lyj
 * @Title: MessageProducerImpl
 * @ProjectName lagou-parent
 * @Description: TODO
 * @date 2021/1/2 11:36
 */
//绑定的通道，output。springcloud stream内对输出通道的定义
@EnableBinding(Source.class)
public class MessageProducerImpl implements IMessageProduder {

    @Autowired
    private Source source;

    @Override
    public void sendMessage(String message) {
        //向mq发送消息（并不直接操作mq，而是操作springcloud stream
        //使用source指定的output通道向外发送消息
        source.output().send(MessageBuilder.withPayload(message).build());
    }
}
